package com.erp.erp_ui.money.controller;

import com.alibaba.fastjson.JSONObject;
import com.erp.enums.DictionaryLxEnum;
import com.erp.enums.DictionaryTypeEnum;
import com.erp.erp_entitys.money.entity.ReceivePaymentDetailEntity;
import com.erp.erp_entitys.money.req.*;
import com.erp.erp_entitys.money.rsp.*;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_entitys.warehouse.req.DictionaryInfoReq;
import com.erp.erp_entitys.warehouse.rsp.CompanyInfoRsp;
import com.erp.erp_ui.base.Base;
import com.erp.erp_ui.money.req.*;
import com.erp.erp_ui.money.service.ReceivePaymentService;
import com.erp.erp_ui.money.vo.*;
import com.erp.erp_ui.warehouse.vo.DepartmentAndBankVo;
import com.erp.erp_ui.warehouse.vo.DictionaryInfoVo;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName : ReceivePaymentController
 * @Description : 资金管理-收款控制层
 * @Author : lst
 * @Date: 2020-12-04 15:09
 */
@Controller
@RequestMapping(value = "receivePayment")
public class ReceivePaymentController extends Base {

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(ReceivePaymentController.class);

    /**
     * 资金管理-收款业务逻辑层接口
     */
    private final ReceivePaymentService receivePaymentService;

    @Autowired
    public ReceivePaymentController(ReceivePaymentService receivePaymentService) {
        this.receivePaymentService = receivePaymentService;
    }


    /**
     * 首页-获取分页信息
     *
     * @param req 查询条件实体
     * @return
     */
    @GetMapping("/getReceivePaymentListByPage")
    @ResponseBody
    public R getReceivePaymentListByPage(ReceivePaymentPageListReq req) {
        try {
            LOGGER.info("资金管理-收款-首页-获取分页信息:" + req.toString());
            PageInfo<ReceivePaymentPageListVo> pageInfo = receivePaymentService.getReceivePaymentListByPage(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-首页-获取分页信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资金管理-收款-登记新增、修改
     *
     * @param req 入参对象
     * @return 新增结果
     */
    @PostMapping("/add")
    @ResponseBody
    public R add(@Validated @RequestBody AddReceivePaymentReq req) {
        try {
            LOGGER.info("资金管理-收款-登记新增 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String name = user.getName();
            String code = user.getCode();
            return receivePaymentService.add(req, name, code);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-登记新增异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 收款认领新增明细
     *
     * @param req 新增数据
     * @return 新增结果
     */
    @PostMapping("/collectionClaimAdd")
    @ResponseBody
    public R collectionClaimAdd(@Validated @RequestBody CollectionClaimAddReq req) {
        try {
            LOGGER.info("资金管理-收款-收款认领新增明细 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String name = user.getName();
            String code = user.getCode();
            return receivePaymentService.collectionClaimAdd(req, name, code);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-收款认领新增明细异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 资金管理-收款-查看详情
     *
     * @param id   收款id
     * @param type 0:查询所有箱体数据 1:只查询确认箱数据 2:只查待确认箱数据
     * @return 对应明细数据
     */
    @GetMapping("/detail")
    @ResponseBody
    public R getDetailInfo(Integer id, Integer type) {
        try {
            LOGGER.info("资金管理-收款-查看详情 id=" + id + ",type=" + type);
            ReceivePaymentDetailVo vo = receivePaymentService.getDetailInfo(id, type);
            return R.build(vo);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-查看详情异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 获取字典信息-币种
     *
     * @return 币种
     */
    @GetMapping("/getCurrencyInfo")
    @ResponseBody
    public R getCurrencyInfo() {
        try {
            LOGGER.info("资金管理-收款-获取字典信息-币种信息");
            //获取所有资源仓库字典信息
            DictionaryInfoReq dictionaryInfosReq = new DictionaryInfoReq();
            //结算相关
            dictionaryInfosReq.setType(DictionaryTypeEnum.SETTLEMENT.getId());
            //币种
            dictionaryInfosReq.setLx(DictionaryLxEnum.CURRENCY.getId());
            List<DictionaryInfoVo> dictionaryInfos = receivePaymentService.getDictionaryInfo(dictionaryInfosReq);
            return R.build(dictionaryInfos);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取字典信息-币种信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 获取公司信息
     *
     * @return 公司信息
     */
    @GetMapping("/getCompanyInfo")
    @ResponseBody
    public R getCompanyInfo() {
        try {
            LOGGER.info("资金管理-收款-获取字典信息-公司信息");
            List<CompanyInfoRsp> companyInfos = receivePaymentService.getCompanyInfo();
            return R.build(companyInfos);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取字典信息-公司信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 通过公司编码获取银行、部门信息
     *
     * @param code 公司编码
     * @return 银行、部门信息
     */
    @GetMapping("/getBankAccountInfo")
    @ResponseBody
    public R getBankAccountInfo(String code) {
        try {
            LOGGER.info("资金管理-收款-获取银行信息-公司信息");
            DepartmentAndBankVo vo = receivePaymentService.getBankAccountInfo(code);
            return R.build(vo);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取银行信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资金管理-收款-获取销售合同信息
     *
     * @param req 查询参数
     * @return 销售合同信息
     */
    @GetMapping("/getImportContractInfoByNotPage")
    @ResponseBody
    public R getImportContractInfoByPage(ImportContractReq req) {
        try {
            LOGGER.info("资金管理-收款-获取销售合同信息 req=" + req.toString());
            PageInfo<ImportContractVo> pageInfo = receivePaymentService.getImportContractInfo(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取销售合同信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资金管理-收款-获取结汇信息
     *
     * @param req 查询参数
     * @return 结汇信息
     */
    @GetMapping("/getImportExchangeInfoByNotPage")
    @ResponseBody
    public R getImportExchangeInfoByPage(ImportExchangeReq req) {
        try {
            LOGGER.info("资金管理-收款-获取结汇信息 req=" + req.toString());
            PageInfo<ImportExchangeInfoVo> pageInfo = receivePaymentService.getImportExchangeInfo(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取结汇信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 获取字典信息-收款类型
     *
     * @return 收款类型
     */
    @GetMapping("/getReceivePaymentTypeInfo")
    @ResponseBody
    public R getReceivePaymentTypeInfo() {
        try {
            LOGGER.info("资金管理-收款-获取字典信息-收款类型信息");
            //获取所有资源仓库字典信息
            DictionaryInfoReq dictionaryInfosReq = new DictionaryInfoReq();
            //结算相关
            dictionaryInfosReq.setType(DictionaryTypeEnum.SETTLEMENT.getId());
            //收款类型
            dictionaryInfosReq.setLx(DictionaryLxEnum.RECEIVE_PAYMENT_TYPE.getId());
            List<DictionaryInfoVo> dictionaryInfos = receivePaymentService.getReceivePaymentTypeInfo(dictionaryInfosReq);
            return R.build(dictionaryInfos);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-获取字典信息-收款类型信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资源管理-收款-删除
     *
     * @param req
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public R deleteInventoryInfo(@RequestBody OperationReq req) {
        try {
            LOGGER.info("资源管理-收款-删除 req=" + req);
            receivePaymentService.delete(req);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-删除异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }

    }

    /**
     * 资源管理-收款-认领确认
     *
     * @param ids 认领确认的明细ids
     * @return 确认结果
     */
    @GetMapping("/addConfirmedStatus")
    @ResponseBody
    public R addConfirmedStatus(String ids, String id) {
        try {
            LOGGER.info("资源管理-收款-认领确认 ids=" + ids);
            UserEntity user = (UserEntity) this.getBean("user");
            receivePaymentService.addConfirmedStatus(ids, id, user);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-认领确认异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 资源管理-收款-一键拆分-获取拆分数据
     *
     * @param id 待拆分主表数据id
     * @return 数据
     */
    @GetMapping("/getSplitData")
    @ResponseBody
    public R getSplitData(String id) {
        try {
            LOGGER.info("资源管理-收款-一键拆分-获取拆分数据 id=" + id);
            List<SplitInfoVo> voList = receivePaymentService.getSplitData(id);
            return R.build(voList);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-一键拆分-获取拆分数据异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 新增一键拆分
     *
     * @param reqList 拆分信息
     * @return 拆分结果
     */
    @PostMapping("/addSplitInfo")
    @ResponseBody
    public R addSplitInfo(@RequestBody List<SplitInfoReq> reqList) {
        try {
            LOGGER.info("资源管理-收款-新增一键拆分 reqList=" + reqList);
            receivePaymentService.addSplitInfo(reqList);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-新增一键拆分异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 一键拆分保存
     *
     * @param reqList 拆分信息
     * @return 拆分结果
     */
    @PostMapping("/saveSplitInfo")
    @ResponseBody
    public R saveSplitInfo(@RequestBody List<SplitInfoReq> reqList) {
        try {
            LOGGER.info("资源管理-收款-一键拆分保存 reqList=" + reqList);
            receivePaymentService.saveSplitInfo(reqList);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-一键拆分保存异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 一键拆分删除
     *
     * @param ids 要删除的拆分id集合
     * @return 删除结果
     */
    @PostMapping("/deleteSplit")
    @ResponseBody
    public R deleteSplit(@RequestBody Integer[] ids) {
        try {
            LOGGER.info("资源管理-收款-一键拆分删除 req=" + ids.toString());
            receivePaymentService.deleteSplit(ids);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-一键拆分删除异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资源管理-收款-退款-获取收款数据
     *
     * @param id 收款主表数据id
     * @return 收款数据
     */
    @GetMapping("/refundAmount/getReceivePaymentInfo")
    @ResponseBody
    public R getReceivePaymentInfo(String id) {
        try {
            LOGGER.info("资源管理-收款-退款-获取收款数据 id=" + id);
            List<SplitInfoVo> voList = receivePaymentService.getReceivePaymentInfo(id);
            return R.build(voList);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-退款-获取收款数据异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 新增退款
     *
     * @param reqList 拆分信息
     * @return 拆分结果
     */
    @PostMapping("/refundAmount/addRefundAmount")
    @ResponseBody
    public R addRefundAmount(@RequestBody List<SplitInfoReq> reqList) {
        try {
            LOGGER.info("资源管理-收款-新增退款 reqList=" + reqList);
            receivePaymentService.addRefundAmount(reqList);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-新增退款异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 资金管理-主页-详情
     *
     * @param id 收款id
     * @return 对应明细数据
     */
    @GetMapping("/getAllDetail")
    @ResponseBody
    public R getAllDetail(Integer id) {
        try {
            LOGGER.info("资金管理-收款-查看详情 id=" + id);
            ReceivePaymentDetailVo vo = receivePaymentService.getAllDetail(id);
            return R.build(vo);
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-查看详情异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 数据操作接口
     *
     * @param req
     * @return
     */
    @PostMapping("/operation")
    @ResponseBody
    public R operation(@RequestBody OperationReq req) {
        try {
            LOGGER.info("仓库管理-资源样品-数据操作接口 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            return receivePaymentService.operation(req, user);
        } catch (Exception e) {
            LOGGER.info("仓库管理-资源样品-数据操作接口异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 资源管理-收款-批量删除
     *
     * @param ids 删除的收款id集合
     * @return 删除结果
     */
    @GetMapping("/batchDelete")
    @ResponseBody
    public R batchDelete(String ids) {
        try {
            LOGGER.info("资源管理-收款-批量删除 ids=" + ids);
            receivePaymentService.batchDelete(ids);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-批量删除异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 资源管理-收款-修改标记颜色
     *
     * @param req 入参实体
     * @return 修改结果
     */
    @PostMapping("/updateMarkColor")
    @ResponseBody
    public R updateMarkColor(@RequestBody OperationReq req) {
        try {
            LOGGER.info("资源管理-收款-修改标记颜色 req=" + req);
            receivePaymentService.updateMarkColor(req);
            return R.build("");
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-修改标记颜色异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    //****************************收款统计*******************************************

    /**
     * 收款金额明细-统计
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics1ListByPage")
    @ResponseBody
    public R collectionStatistics1ListByPage(CollectionStatistics1Req req) {
        try {
            LOGGER.info("资源管理-收款-水单金额明细统计 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            PageInfo<CollectionStatistics1Rsp> pageInfo = receivePaymentService.collectionStatistics1ListByPage(req, code);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-水单金额明细统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 收款金额明细-导出
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics1Export")
    @ResponseBody
    public R collectionStatistics1Export(CollectionStatistics1Req req) {
        try {
            LOGGER.info("资源管理-收款-收款金额明细-导出 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            JSONObject info= receivePaymentService.collectionStatistics1Export(req, code);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-收款金额明细-导出异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 按发票应收款统计 或者 按发票应收统计价格术语不同--分页
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics2ListByPage")
    @ResponseBody
    public R collectionStatistics2ListByPage(CollectionStatistics2Req req) {
        try {
            LOGGER.info("资源管理-收款-水单金额明细统计 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            PageInfo<CollectionStatistics2Rsp> pageInfo = receivePaymentService.collectionStatistics2ListByPage(req, code);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-水单金额明细统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 按发票应收款统计 或者 按发票应收统计价格术语不同 --导出
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("export/getContractStatisticsTwoExport")
    @ResponseBody
    public R collectionStatisticsTwoExport(CollectionStatistics2Req req) {
        try {
            LOGGER.info("资源管理-收款-按发票应收款统计--导出 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            JSONObject info=  receivePaymentService.collectionStatisticsTwoExport(req, code);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-按发票应收款统计--导出异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 业务员年度认领金额统计--分页
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics3ListByPage")
    @ResponseBody
    public R collectionStatistics3ListByPage(CollectionStatistics3Req req) {
        try {
            LOGGER.info("资源管理-收款-水单金额明细统计 req=" + req);
            PageInfo<CollectionStatistics3Rsp> pageInfo = receivePaymentService.collectionStatistics3ListByPage(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-水单金额明细统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 业务员年度认领金额统计--导出
     *
     * @param req 入参实体
     * @return
     */
    @RequestMapping("getContractStatisticsThirdExport")
    @ResponseBody
    public R collectionStatisticsThirdExport(CollectionStatistics3Req req) {
        try {
            LOGGER.info("资源管理-收款-业务员年度认领金额统计--导出 req=" + req);
            JSONObject info=   receivePaymentService.collectionStatisticsThirdExport(req);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-业务员年度认领金额统计--导出异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 按合同应收款统计--分页
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics4ListByPage")
    @ResponseBody
    public R collectionStatistics4ListByPage(CollectionStatistics4Req req) {
        try {
            LOGGER.info("资源管理-收款-按合同应收款统计 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            PageInfo<CollectionStatistics4Rsp> pageInfo = receivePaymentService.collectionStatistics4ListByPage(req, code);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-按合同应收款统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 按合同应收款统计--导出
     * @param req 入参实体
     * @return
     */
    @RequestMapping("getContractStatisticsFourthExport")
    @ResponseBody
    public R collectionStatisticsFourthExport(CollectionStatistics4Req req) {
        try {
            LOGGER.info("资源管理-收款-按合同应收款统计--导出 req=" + req);
            UserEntity user = (UserEntity) this.getBean("user");
            String code = user.getCode();
            JSONObject info=   receivePaymentService.collectionStatisticsFourthExport(req, code);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-按合同应收款统计--导出异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 获取本月待认领水单
     *
     * @return 本月待认领水单
     */
    @GetMapping("/statistics/getBillNoCount")
    @ResponseBody
    public R getBillNoCount() {
        try {
            LOGGER.info("资源管理-收款-获取本月待认领水单");
            UserEntity user = (UserEntity) this.getBean("user");
            String name = user.getName();
            String code = user.getCode();
            long count = receivePaymentService.getBillNoCount(name, code);
            return R.build(count);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-获取本月待认领水单异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * FQ利润统计--分页
     *
     * @return FQ利润统计
     */
    @GetMapping("/statistics/getProfitStatisticsInfoByPage")
    @ResponseBody
    public R getProfitStatisticsInfo(ProfitStatisticsReq req) {
        try {
            LOGGER.info("资源管理-收款-FQ利润统计:req=" + req.toString());
            PageInfo<ProfitStatisticsVo> pageInfo = receivePaymentService.getProfitStatisticsInfo(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-FQ利润统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * FQ利润统计--导出
     *
     * @return FQ利润统计
     */
    @GetMapping("/export/getContractStatisticsFQExport")
    @ResponseBody
    public R getContractStatisticsFQExport(ProfitStatisticsReq req) {
        try {
            LOGGER.info("资源管理-收款-FQ利润统计:req=" + req.toString());
            JSONObject info=   receivePaymentService.collectionStatisticsFQExport(req);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-FQ利润统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }



    /**
     * 根据发票编号获取收款主表id(多个id以英文逗号隔开)
     * @param billNo 发票编号
     * @return 收款主表id(多个id以英文逗号隔开)
     */
    @GetMapping("/statistics/getReceivePaymentId")
    @ResponseBody
    public R getReceivePaymentId(String billNo) {
        try {
            LOGGER.info("资源管理-收款-根据发票编号获取收款主表id:billNo=" + billNo);
            String ids = receivePaymentService.getReceivePaymentId(billNo);
            return R.build(ids);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-根据发票编号获取收款主表id异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 获取新的收款单号
     * @return 新的收款单号
     */
    @GetMapping("/getReceivePaymentBillNo")
    @ResponseBody
    public R getReceivePaymentBillNo(){
        try {
            LOGGER.info("资金管理-收款-获取新的收款单号");
            String billNo = receivePaymentService.getReceivePaymentBillNo();
            return R.build(billNo);
        }catch (Exception e){
            LOGGER.info("资金管理-收款-获取新的收款单号异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 产品统计-分页
     *
     * @param req 查询条件
     * @return 产品统计
     */
    @GetMapping("/productStatisticsByPage")
    @ResponseBody
    public R productStatisticsByPage(ProductStatisticsReq req) {
        try {
            LOGGER.info("资金管理-收款-产品统计 req=" + req.toString());
            PageInfo<ProductStatisticsRsp> pageInfo = receivePaymentService.getProductStatisticsByPage(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-产品统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 产品统计-导出
     * @param req 入参实体
     * @return
     */
    @RequestMapping("productStatisticsExport")
    @ResponseBody
    public R productStatisticsExport(ProductStatisticsReq req) {
        try {
            LOGGER.info("资源管理-收款-产品统计-导出 req=" + req);
            JSONObject info = receivePaymentService.productStatisticsExport(req);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-产品统计-导出 异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 产品出货详情统计--分页
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatistics6ListByPage")
    @ResponseBody
    public R collectionStatistics6ListByPage(CollectionStatistics6Req req) {
        try {
            LOGGER.info("资源管理-收款-产品出货详情统计--分页 req=" + req);
            PageInfo<CollectionStatistics6Rsp> pageInfo = receivePaymentService.collectionStatistics6ListByPage(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-产品出货详情统计--分页异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 产品出货详情统计--导出
     * @param req 入参实体
     * @return
     */
    @RequestMapping("collectionStatisticsSixExport")
    @ResponseBody
    public R collectionStatisticsSixExport(CollectionStatistics6Req req) {
        try {
            LOGGER.info("资源管理-收款-产品出货详情统计--导出 req=" + req);
            JSONObject info = receivePaymentService.collectionStatisticsSixExport(req);
            return R.build(info);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-产品出货详情统计--导出异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 资源管理-收款-通过外销合同号获取收款明细信息
     *
     * @param contractNo 外销合同号
     * @return 通过外销合同号获取收款明细信息
     */
    @RequestMapping("/getReceivePaymentByContractNo")
    @ResponseBody
    public R getReceivePaymentByContractNo(String contractNo) {
        try {
            LOGGER.info("资源管理-收款-通过外销合同号获取收款明细信息 contract=" + contractNo);
            List<ReceivePaymentDetailEntity> detailList = receivePaymentService.getReceivePaymentByContractNo(contractNo);
            return R.build(detailList);
        } catch (Exception e) {
            LOGGER.info("资源管理-收款-通过外销合同号获取收款明细信息异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 产品统计-分页
     *
     * @param req 查询条件
     * @return 产品统计
     */
    @GetMapping("/statistics/getOrderDetailByPage")
    @ResponseBody
    public R getOrderDetailByPage(OrderDetailReq req) {
        try {
            LOGGER.info("资金管理-收款-订单详情统计 req=" + req.toString());
            PageInfo<OrderDetailVo> pageInfo = receivePaymentService.getOrderDetailByPage(req);
            return R.build(0, "", pageInfo.getTotal(), pageInfo.getList());
        } catch (Exception e) {
            LOGGER.info("资金管理-收款-订单详情统计异常:" + e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 查询该销售是否已经关联收款，如果是，则不能修改币种和汇率
     * @return
     */
    @RequestMapping("isLinkedCollections")
    @ResponseBody
    public R isLinkedCollections(String contractCode){
        try {
            boolean flag=receivePaymentService.isLinkedCollections(contractCode);
            return R.build(flag);
        } catch (Exception e) {
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 根据外销号 查询收汇金额的合计
     * @return
     */
    @RequestMapping("getLinkedCollectionsAmount")
    @ResponseBody
    public R getLinkedCollectionsAmount(String contractCode){
        try {
            Double result=receivePaymentService.getLinkedCollectionsAmount(contractCode);
            return R.build(result);
        } catch (Exception e) {
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

}
